home *** CD-ROM | disk | FTP | other *** search
- #include <NameRegistry.h>
- #include <PCCard.h>
- #include <MixedMode.h>
- #include <Errors.h>
-
- #ifdef __powerc
- enum {
- uppEjectPCCardsProcInfo = kPascalStackBased
- | RESULT_SIZE (SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- };
- ProcInfoType __procinfo = uppEjectPCCardsProcInfo;
- #endif
-
- pascal OSStatus EjectPCCards (long slot);
-
- /*
- This routine will search through the name registry to find PC Card cards. It will
- then issue an eject call via PCCardEject for the requested cards. Cards that do
- not eject for some reason (usually because they are in use) are ignored and no
- attempt is made to make the card un-busy and then eject it.
-
- slot == 0 -- eject all cards
- slot == 1 -- eject lower card
- slot == 2 -- eject upper card
- */
- pascal OSStatus EjectPCCards (long slot) {
- OSStatus err = noErr;
- RegEntryIter cookie = nil;
- RegEntryID pccardEntry;
- RegEntryIterationOp iterOp = kRegIterDescendants;
- Boolean done = false;
- OSType nodeType = 'pccc';
- long socketNumber = -1; /* a safe value */
- RegPropertyValueSize size = sizeof (long);
-
- if (slot < 0 || slot > 2) {
- err = paramErr;
- }
-
- if (err == noErr) {
- err = RegistryEntryIDInit (&pccardEntry);
- }
-
- if (err == noErr) {
- err = RegistryEntryIterateCreate (&cookie);
- }
-
- if (err == noErr) {
- do {
- err = RegistryEntrySearch (&cookie, iterOp, &pccardEntry, &done, "PCCardNodeType", &nodeType, sizeof (OSType));
-
- if (!done && err == noErr) {
- /* Get the socket number so we eject only the requested slots. */
- err = RegistryPropertyGet (&pccardEntry, "SocketNumber", &socketNumber, &size);
- }
-
- if (!done && err == noErr && ((slot - 1) == socketNumber || slot == 0)) {
- (void)PCCardEject (&pccardEntry);
- (void)RegistryEntryIDDispose (&pccardEntry);
- }
-
- iterOp = kRegIterContinue;
- } while (!done && err == noErr);
- }
-
- (void)RegistryEntryIterateDispose (&cookie);
-
- return err;
- }
-
- #if DEBUG
- void main (void) {
- EjectPCCards (0);
- }
- #endif
-